<template>
  <div>
    <el-container style="height:700px; border: 1px solid #eee">
      <el-header style="font-size: 40px; background-color: white;">威海环海自驾汽车租凭管理系统</el-header>
      <el-container>
        <el-aside width="230px" style="border: 1px solid #eee">
          <el-menu :default-openeds="['1', '3']">

            <el-submenu index="1">
              <template slot="title"><i class="el-icon-message"></i>系统信息管理</template>
              <el-menu-item-group>
                <el-menu-item index="1-1">
                  <router-link :to="{ path: '/manager/managerPersonal', query: { userAcct: $route.query.userAcct } }">个人信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-2">
                  <router-link :to="{ path: '/manager/clientInfo', query: { userAcct: $route.query.userAcct } }">客户信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-3">
                  <router-link :to="{ path: '/manager/clientAcct', query: { userAcct: $route.query.userAcct } }">客户账户管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-4">
                  <router-link :to="{ path: '/manager/saleInfo', query: { userAcct: $route.query.userAcct } }">业务员信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-5">
                  <router-link :to="{ path: '/manager/carInfo', query: { userAcct: $route.query.userAcct } }">车辆信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-6">
                  <router-link :to="{ path: '/manager/leaseInfo', query: { userAcct: $route.query.userAcct } }">租凭登记信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-7">
                  <router-link :to="{ path: '/manager/returnInfo', query: { userAcct: $route.query.userAcct } }">租凭归还信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-8">
                  <router-link :to="{ path: '/manager/rechargeInfo', query: { userAcct: $route.query.userAcct } }">充值信息管理</router-link>
                </el-menu-item>
                <el-menu-item index="1-9">
                  <router-link :to="{ path: '/manager/deductInfo', query: { userAcct: $route.query.userAcct } }">扣款信息管理</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title"><i class="el-icon-s-goods"></i>交易模块</template>
              <el-menu-item-group>
                <el-menu-item index="2-1">
                  <router-link :to="{ path: '/manager/carlease', query: { userAcct: $route.query.userAcct } }">汽车租凭</router-link>
                </el-menu-item>
                <el-menu-item index="2-1">
                  <router-link :to="{ path: '/manager/carreturn', query: { userAcct: $route.query.userAcct } }">汽车归还</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

          </el-menu>
        </el-aside>

        <el-main>

          <!-- 归还车辆的对话框 -->
          <el-dialog title="归还车辆" :visible.sync="addDialogVisible">
            <el-form :model="editForm" label-width="100px">
              <el-form-item label="归还日期">
                <el-date-picker v-model="editForm.returntime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
              </el-form-item>
              <el-form-item label="租期内费用">
                <el-input v-model="editForm.expend"></el-input>
              </el-form-item>
              <el-form-item label="超期费用">
                <el-input v-model="editForm.overdueExpend"></el-input>
              </el-form-item>
              <el-form-item label="车辆损坏费用">
                <el-input v-model="editForm.damageExpend" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-input>
              </el-form-item>
              <el-form-item label="总费用">
                <el-input v-model="editForm.totalExpend" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="handleAddSave">确定</el-button>
              <el-button @click="addDialogVisible = false">取消</el-button>
            </div>
          </el-dialog>

          <!-- 表格 -->
          <el-table :data="tableData" border>
            <el-table-column prop="checkID" label="租凭单号" width="auto"></el-table-column>
            <el-table-column prop="clientID" label="客户编号" width="auto"></el-table-column>
            <el-table-column prop="clientName" label="客户姓名" width="auto"></el-table-column>
            <el-table-column prop="carID" label="车辆编号" width="auto"></el-table-column>
            <el-table-column prop="dailyExpend" label="每日费用" width="80px"></el-table-column>
            <el-table-column prop="overdueDailyExpend" label="超期每日费用" width="110px"></el-table-column>
            <el-table-column prop="day" label="租凭天数" width="80px"></el-table-column>
            <el-table-column prop="leasetime" label="租凭日期" width="100px"></el-table-column>
            <el-table-column prop="timeToReturn" label="应还日期" width="100px"></el-table-column>
            <el-table-column label="操作" v-slot="scope">
              <el-button type="primary" size="mini" @click="handleAdd($event, scope)">归还</el-button>
            </el-table-column>
          </el-table>

          <br><br>

        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false, // 对话框是否可见
      addDialogVisible: false,
      editForm: {           // 要输入的租凭归还信息
        returntime: '',
        expend: '',
        overdueExpend: '',
        damageExpend: '',
        totalExpend: ''
      },
    }
  },
  methods: {
    onSubmit:function(){
      alert("查询数据");
    },
    handleSizeChange: function (val) {
      alert("每页记录数变化" + val);
    },
    handleCurrentChange: function (val) {
      alert("页码发生变化" + val);
    },
    handleAdd(event, scope) {
      // 获取当前行的数据
      const rowData = scope.row;

      // 将需要的数据存储到editForm中
      this.editForm = {
        checkID: rowData.checkID,
        clientID: rowData.clientID,
        clientName: rowData.clientName,
        carID: rowData.carID,
        leasetime: rowData.leasetime,
        timeToReturn: rowData.timeToReturn,
        returntime:  '',
        expend: '',
        overdueExpend: '',
        damageExpend: '',
        totalExpend: ''
      };

      this.addDialogVisible = true;
    },
    handleAddSave() {
      const data = {
        checkID: this.editForm.checkID,
        clientID: this.editForm.clientID,
        clientName: this.editForm.clientName,
        carID: this.editForm.carID,
        leasetime: this.editForm.leasetime,
        timeToReturn: this.editForm.timeToReturn,
        returntime: this.editForm.returntime,
        expend: this.editForm.expend,
        overdueExpend: this.editForm.overdueExpend,
        damageExpend: this.editForm.damageExpend,
        totalExpend: this.editForm.totalExpend
      };
      axios.post('http://localhost:8081/returnInfo/insert', data)
          .then(response => {
            console.log(response);
            this.$message.success('归还成功');
            this.addDialogVisible = false;
            // 新增成功后，重新获取数据刷新表格
            this.getTableData();
          })
          .catch(error => {
            console.log(error);
          });
    },
    // 获取车辆信息的数据并刷新表格
    getTableData() {
      axios.get("http://localhost:8081/leaseInfo/select3").then((result) => {
        this.tableData = result.data.data;
      });
    },
  },
  mounted() {
    //发送异步请求，获取数据
    axios.get("http://localhost:8081/leaseInfo/select3").then((result) => {
      this.tableData=result.data.data;
    });
  },

}
</script>

<style>

</style>